import axios from 'axios'
import { Toast } from 'vant';

var service = axios.create({
    timeout:10*1000,
    baseURL:'/api'
})

service.interceptors.request.use(
    (config)=>{
        config.headers['token'] = 'abc' + localStorage.getItem('token');
        config.headers['x-token'] = 'erlu';
        Toast.loading({ message: '加载中...', duration: 0 });
        return config;
    },(error)=>{
        return Promise.reject(error);
    }
)

service.interceptors.response.use(
    (res)=>{
        Toast.clear();
        return res;
    },(error)=>{
        Toast.clear();
        if (error.response.status == 401) {
            console.log('身份认证过期,请重新登录!');
        }
        else if (error.response.status == 404) {
            console.log('访问路径有误!');
        }
        else if (error.response.status == 500) {
            console.log('服务器内部错误! 请联系管理员处理!');
        }
    }
)

export default service;